#include <bits/stdc++.h>
using namespace std;

inline int read() {
	int x = 0, f = 0; char ch = getchar();
	while (ch < '0' or ch > '9') f |= (ch == '-'), ch = getchar();
	while (ch >= '0' and ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

int __stk[128], __top;
inline void write(int x) {
    if(x < 0) putchar('-'), x = -x;
	do { __stk[++__top] = x % 10, x /= 10; } while (x);
	while (__top) putchar(__stk[__top--] + '0');
}

const int mod = 998244353;

void Min(int &x, int y) { y < x and (x = y); }
void Max(int &x, int y) { y > x and (x = y); }

void inc(int &x, int y) { (x += y) >= mod and (x -= mod); }
void mul(int &x, int y) { x = 1ll * x * y % mod; }

int q_pow(int x, int k) { int res = 1; for (; k; k >>= 1, mul(x, x)) if (k & 1) mul(res, x); return res; }

bool stmer;

const int N = 1e5 + 100, M = 20;

int n, m, q;

vector<int> e[N];

namespace sub1 {
	const int S = 1 << 20;

	int Ans[S][5];
	int d[N], rnk[N], to[N], To[N], fa[N][M], dep[N];

	vector<int> u;

	int lca(int x, int y) {
		if (!x or !y) return x | y;
		if (dep[x] < dep[y]) swap(x, y);
		for (int i = M - 1; i + 1; i--) if (dep[fa[x][i]] >= dep[y]) x = fa[x][i];
		if (x == y) return x;
		for (int i = M - 1; i + 1; i--) if (fa[x][i] ^ fa[y][i]) x = fa[x][i], y = fa[y][i];
		return fa[x][0];
	}

	void init() {
		for (int i = 1; i <= n; i++) {
			to[i] = 1 << i - 1, To[i] = 1 << i - 1;
			for (int v : e[i]) d[v]++;
		}

		queue<int> q; int cnt = 0;
		for (int i = 1; i <= n; i++) if (!d[i]) q.push(i);

		while (!q.empty()) {
			int x = q.front(); q.pop(), rnk[++cnt] = x, dep[x] = dep[fa[x][0]] + 1;
			for (int i = 1; i < M; i++) fa[x][i] = fa[fa[x][i - 1]][i - 1];
			for (int v : e[x]) {
				fa[v][0] = lca(fa[v][0], x);
				if (!(--d[v])) q.push(v);
			}
		}

		for (int i = n; i; i--) {
			int u = rnk[i];	to[fa[u][0]] |= to[u];
			for (int v : e[u]) To[u] |= To[v];
		}
	}

	void main() {
		init();
		for (int i = 1; i < 1 << n; i++) {
			int op = __builtin_popcount(i); if (op > 4) continue;
			for (int s = 1; s < 1 << n; s++) {
				int p = s; Ans[s][op]++; bool flag = 1;
				for (int j = 0; j < n; j++) if (i >> j & 1) {
					int x = s & to[j + 1], y = p & to[j + 1], z = s & To[j + 1];
					if (!x or x != y or x != z) { flag = 0, Ans[s][op]--; break; }
					p ^= y;
				}
				if (flag and p) Ans[s][op]--;
			}
		}

		while (q--) {
			int k = read(), p = read(), s = 0;
			for (int i = 1; i <= p; i++) s |= 1 << read() - 1;
			write(Ans[s][k]), putchar('\n');
		}
	}
}

struct Ask {
	int k;
	vector<int> p; 
} Q[N];

namespace Tree {

	int rnk[N], d[N];
	int fa[N][M], dep[N];

	int lca(int x, int y) {
		if (!x or !y) return x | y;
		if (dep[x] < dep[y]) swap(x, y);
		for (int i = M - 1; i + 1; i--) if (dep[fa[x][i]] >= dep[y]) x = fa[x][i];
		if (x == y) return x;
		for (int i = M - 1; i + 1; i--) if (fa[x][i] ^ fa[y][i]) x = fa[x][i], y = fa[y][i];
		return fa[x][0];
	}

	void init() {
		queue<int> q; int cnt = 0;
		for (int i = 1; i <= n; i++) if (!d[i]) q.push(i);

		while (!q.empty()) {
			int x = q.front(); 
			q.pop(), rnk[++cnt] = x, dep[x] = dep[fa[x][0]] + 1;
			for (int i = 1; i < M; i++) fa[x][i] = fa[fa[x][i - 1]][i - 1];

			for (int v : e[x]) {
				fa[v][0] = lca(fa[v][0], x);
				if (!(--d[v])) q.push(v);
			}
		}
	}
}

namespace sub2 {
	bool check() {
		for (int i = 1; i <= q; i++) if (Q[i].k != 1) return 0;
		return 1;
	}

	void main() {
		Tree :: init();
		for (int i = 1; i <= q; i++) {
			int x = 0;
			for (int y : Q[i].p) x = Tree :: lca(x, y);
			write(Tree :: dep[x]), putchar('\n');
		}
	}
}

bool edmer;
signed main() {
	freopen("lodge.in", "r", stdin);
	freopen("lodge.out", "w", stdout);
	cerr << "[Memory] " << (&stmer - &edmer) / 1024 / 1024 << " MB\n";

	n = read(), m = read(), q = read();
	for (int i = 1; i <= m; i++) {
		int u = read(), v = read();
		e[u].push_back(v);
	}

	if (n <= 10 and m <= 20) sub1 :: main();
	else {
		for (int i = 1; i <= q; i++) {
			Q[i].k = read(); int k = read();
			while (k--) Q[i].p.push_back(read());
		}
		if (sub2 :: check()) sub2 :: main();
	}

    cerr << "[Runtime] " << (double) clock() / CLOCKS_PER_SEC << " seconds\n";
	return 0;
} 